----------------------------------Spell Variables--------------------------------------
SPELL.m_iSpellID = 48412 -- Whatever value you want as long as it doesn't override any other spells' IDs.
SPELL.m_iRange = 0
SPELL.m_sName = "Quick Slide"
SPELL.m_sToolTip = [[Causes you to slide
					backwards rapidly. Reactivating
					this ability moves you forwards
					the same distance.]]
SPELL.m_sIcon = "devin/blackbetty/spells/brawler/quickslideback.png"
SPELL.m_sReplaceIcon = "devin/blackbetty/spells/brawler/quickslideforward.png"
SPELL.m_bRequiresTarget = false
SPELL.m_iCoolDown = 10
SPELL.m_iSpellType = SPELLTYPE_MOBILITY
SPELL.m_bRecastWhileCasting = true

---------------------------------------------------------------------------------------

local range = 100
local weapondamage = 10
local uppercut_time = false

function SPELL:Cast( pl, target )
	pl:EmitSound("devin/blackbetty/weapons/Charge.wav", 160, 100)
	pl:SetVelocity(pl:GetVelocity()*-1)
	ParticleEffectAttach( "whirlwind", PATTACH_POINT_FOLLOW, pl, pl:LookupAttachment("rightfoot"))
	ParticleEffectAttach( "whirlwind", PATTACH_POINT_FOLLOW, pl, pl:LookupAttachment("leftfoot"))
	local subtractedvectors = (pl:GetPos()) - (pl:GetPos() + pl:GetAngles():Forward()*-512)
	local subtractedvectorsnorm = (pl:GetPos()) - (pl:GetPos() + pl:GetAngles():Forward()*-512)
	subtractedvectorsnorm:Normalize()
	pl:SetPos(pl:GetPos() + Vector(0, 0, 16))
	pl:SetVelocity(-(subtractedvectorsnorm*(4*subtractedvectors:Length()+128)))
	timer.Simple(0.2, function()
		pl:SetVelocity(pl:GetVelocity()*-1) 
	end)
	if(timer.Exists(""..pl:EntIndex().."quickslideforwards"))then
		timer.Destroy(""..pl:EntIndex().."quickslideforwards")
	end
	timer.Create(""..pl:EntIndex().."quickslideforwards", 3, 1, function()
		pl.FailedToPress = true
		net.Start("UseIconFromSpell")
		net.WriteFloat(self.m_iSpellID)
		net.Send(pl)
	end)
end

function SPELL:Recast( pl, target )
	if(timer.Exists(""..pl:EntIndex().."quickslideforwards"))then
		timer.Destroy(""..pl:EntIndex().."quickslideforwards")
	end
	if(!pl.FailedToPress)then
		pl:EmitSound("devin/blackbetty/weapons/Charge.wav", 160, 100)
		pl:SetVelocity(pl:GetVelocity()*-1)
		ParticleEffectAttach( "whirlwind", PATTACH_POINT_FOLLOW, pl, pl:LookupAttachment("rightfoot"))
		ParticleEffectAttach( "whirlwind", PATTACH_POINT_FOLLOW, pl, pl:LookupAttachment("leftfoot"))
		local subtractedvectors = (pl:GetPos()) - (pl:GetPos() + pl:GetAngles():Forward()*512)
		local subtractedvectorsnorm = (pl:GetPos()) - (pl:GetPos() + pl:GetAngles():Forward()*512)
		subtractedvectorsnorm:Normalize()
		pl:SetPos(pl:GetPos() + Vector(0, 0, 16))
		pl:SetVelocity(-(subtractedvectorsnorm*(4*subtractedvectors:Length()+128)))
		timer.Simple(0.2, function()
			pl:SetVelocity(pl:GetVelocity()*-1) 
		end)
	end
	pl.FailedToPress = false
	pl:SetNWBool("Casting", false)
	pl:SetNWBool("Casted", false)
end

